package com.xbao.service.impl;

import com.xbao.core.config.BusBean;
import com.xbao.core.config.BusConfig;
import com.xbao.service.BusConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
 * Created by qingshengzheng on 2019/1/23.
 */
@Service
public class BusConfServiceImpl implements BusConfService {
    @Autowired
    private BusConfig busConfig;

    @Override
    public HashMap<String, List<BusBean>> getConfig() {
       HashMap<String,String> map= busConfig.getConfig();
        HashMap<String,List<BusBean>> temp=new HashMap<String,List<BusBean>>();
        Iterator keyIterator=map.keySet().iterator();
        while(keyIterator.hasNext()){
            List<BusBean> beans=new ArrayList<>();
            String key= (String) keyIterator.next();
            String v=map.get(key);
            String[] vs=v.split(";");
            for(String a:vs){
                String[] b=a.split(",");
                BusBean bean=new BusBean(b[0],b[1]);
                beans.add(bean);
            }
            temp.put(key,beans);
        }
        return temp;
    }
}
